package dfd.diagram.edit.policies;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;

import dfd.diagram.edit.commands.AndCreateCommand;
import dfd.diagram.edit.commands.EndCreateCommand;
import dfd.diagram.edit.commands.OrCreateCommand;
import dfd.diagram.edit.commands.ProcessCreateCommand;
import dfd.diagram.edit.commands.StartCreateCommand;
import dfd.diagram.edit.commands.StorageCreateCommand;
import dfd.diagram.edit.commands.XorCreateCommand;
import dfd.diagram.providers.DfdElementTypes;

/**
 * @generated
 */
public class DfdItemSemanticEditPolicy extends DfdBaseItemSemanticEditPolicy {

	/**
	 * @generated
	 */
	public DfdItemSemanticEditPolicy() {
		super(DfdElementTypes.Dfd_1000);
	}

	/**
	 * @generated
	 */
	protected Command getCreateCommand(CreateElementRequest req) {
		if (DfdElementTypes.And_2001 == req.getElementType()) {
			return getGEFWrapper(new AndCreateCommand(req));
		}
		if (DfdElementTypes.Process_2002 == req.getElementType()) {
			return getGEFWrapper(new ProcessCreateCommand(req));
		}
		if (DfdElementTypes.Xor_2003 == req.getElementType()) {
			return getGEFWrapper(new XorCreateCommand(req));
		}
		if (DfdElementTypes.Start_2004 == req.getElementType()) {
			return getGEFWrapper(new StartCreateCommand(req));
		}
		if (DfdElementTypes.Or_2005 == req.getElementType()) {
			return getGEFWrapper(new OrCreateCommand(req));
		}
		if (DfdElementTypes.End_2006 == req.getElementType()) {
			return getGEFWrapper(new EndCreateCommand(req));
		}
		if (DfdElementTypes.Storage_2007 == req.getElementType()) {
			return getGEFWrapper(new StorageCreateCommand(req));
		}
		return super.getCreateCommand(req);
	}

	/**
	 * @generated
	 */
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
				.getEditingDomain();
		return getGEFWrapper(new DuplicateAnythingCommand(editingDomain, req));
	}

	/**
	 * @generated
	 */
	private static class DuplicateAnythingCommand extends
			DuplicateEObjectsCommand {

		/**
		 * @generated
		 */
		public DuplicateAnythingCommand(
				TransactionalEditingDomain editingDomain,
				DuplicateElementsRequest req) {
			super(editingDomain, req.getLabel(), req
					.getElementsToBeDuplicated(), req
					.getAllDuplicatedElementsMap());
		}

	}

}
